package com.demoworld;

import io.redisearch.Query;
import io.redisearch.Schema;
import io.redisearch.SearchResult;
import io.redisearch.client.Client;
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by francis on 2017/7/11.
 */
public class SearchTest {
    @Test
    public void createIndexTest1() {
        Client client = new Client("demoworld", "192.168.222.130", 6380, 1000, 2);
        Schema sc = new Schema()
                .addTextField("title", 5.0)
                .addTextField("body", 1.0)
                .addNumericField("price");
        client.createIndex(sc, Client.IndexOptions.Default());
        Map<String, Object> fields = new HashMap<>();
        fields.put("title", "hello world");
        fields.put("body", "lorem ipsum");
        fields.put("price", 1337);
//        redis.clients.jedis.commands.ProtocolCommand
        Assert.assertEquals(true, client.addDocument("doc1", fields));
    }

    @Test
    public void search1() {
        Client client = new Client("demoworld", "192.168.222.130", 6380, 1000, 20);
        Query q = new Query("hello world")
                .addFilter(new Query.NumericFilter("price", 0, 1000))
                .limit(0, 5);
        SearchResult res = client.search(q);
    }
}
